var myDate = new Date();
var year = myDate.getFullYear();   //获取完整的年份(4位,1970-????)
var month =myDate.getMonth()+1;      //获取当前月份(0-11,0代表1月)
var day = myDate.getDate();       //获取当前日(1-31)
if(month<10)month="0"+month;
if(day<10)day="0"+day;
var tody = year+"-"+month+"-"+day;
var userinfo = null;
var check_id = '';
var usermaneDemp = '';
$(document).ready(function(){
	var url = window.location;
	check_id= cw.common.getQueryString(url,"CHECKID");
	cw.common.getUserSession(getUserInfo);//查询用户
});
var getUserInfo = function(us){
	userinfo=us;
	$("#createBy").html(userinfo.USER_NAME);
	$("#createDate").html(tody);
	//queryDEPARTMENT();//查询用户管理部门
	QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION();
}
//查询部门
var queryDEPARTMENT = function(){
	$.post(cw.common.path+'/json',
			{
				action : 'QUERY_USER_DEPART_ACTION',
				USER_ID:userinfo.USER_ID
			}, function(data){
				if (data.success) {
					var length = data.root.T_USER_DEPARTMENT.rs.length;
					if(length > 0){
						for(var i=0;i<length;i++) {
							var obj=data.root.T_USER_DEPARTMENT.rs[i];
							usermaneDemp+=obj.DEPARTMENT_NO+","
						}
					}
				} else {
					alert(data.errors.errmsg);
				}
				usermaneDemp+='0';
				QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION();
			}, 'json');
}
//资产详细信息
var QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION = function(){
	
	var barcode = $('#BARCODE').val();
	if(barcode==undefined)barcode='';
	var url = cw.common.path + '/json?action=QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION';
	url += "&CHECK_NO="+check_id;
	url += "&BARCODE="+barcode;
	url += "&ISCHECK=0";
	//url += "&DEPARTMENT_NAME="+usermaneDemp;
	var xmlname = "T_CHECK_INFO_DETAIL";
	var pagePanel='#T_CHECK_INFO_DETAIL_pager';
	var result='#T_CHECK_INFO_DETAIL_LIST';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION,pagePanel,defaultHtml);
}
var fn_QUERY_T_CHECK_INFO_DETAILBY_PAGER_ACTION = function(obj,result,i){
	var str='<li id="bar_'+obj.ID+'-'+obj.BARCODE+'">';
	str+='<em style="width: 10%; text-align: center;"><input type="checkbox" id="check_'+obj.ID+'" name="check" value="'+obj.ID+'-'+obj.BARCODE+'" /></em>';
	str+='<em style="width: 10%; text-align: center;">'+obj.BARCODE+'</em>';
	str+='<em style="width: 12%; text-align: center;">'+obj.FIXED_ASSETS_NAME+'</em>';
	str+='<em style="width: 12%; text-align: center;">'+obj.DEPARTMENT_NAME+'</em>';
	str+='<em style="width: 12%; text-align: center;">'+obj.STORED_IN+'</em>';
	str+='<em style="width: 12%; text-align: center;">'+obj.WITH_MANANGER+'</em>';
	str+='<em style="width: 12%; text-align: center;"><a href="javascript:chekDetial(\''+obj.ID+'\')">盘点</a></em>';
	str+='</li>';
	$(result).append(str);
}

var chekDetial =function(chid){
	$("#check_"+chid).attr("checked",true);
	batchCheck();
}

//批量删除
function batchCheck(){
	if(getCheckedNum('check')==0){
		alert('请选择要盘点的资产条码');
		return;
	}
	if(!confirm('确定要盘点资产吗？')){
		return;
	}
	var barcodeA = getCheckedVal('check').split(',');
	$.post(cw.common.path + '/json',
		{
			action : 'BATCH_CHECK_T_CHECK_INFO_DETAIL_ACTION',
			ID : barcodeA,
			CHECK_NO:check_id
		}, function(data){
			if (data.success) {
				for(var i=0;i<barcodeA.length;i++)
				{
					$("#bar_"+barcodeA[i]).remove();
				}
				alert('批量盘点资产成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
}